package com.cl.mypureframe.kotlin

import android.app.Activity
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.annotation.Nullable
import androidx.core.app.ActivityCompat

/**
 * @Class: MainKtActivity
 * @Description:
 * @Author: ChenLei
 * @Date: 2020/12/23---16:53
 */
class MainKtActivity {

    fun main() {
        val x = 0
        when (x) {
            0, 1 -> println("x == 0 or x == 1")
            else -> println("otherwise")
        }

        when (x) {
            1 -> println("x == 1")
            2 -> println("x == 2")
            else -> { // 注意这个块
                println("x 不是 1 ，也不是 2")
            }
        }

        when (x) {
            in 0..10 -> println("x 在该区间范围内")
            else -> println("x 不在该区间范围内")
        }

        val jack = User(name = "Jack", age = 1)
        val olderJack = jack.copy(age = 2)
        println(jack)
        println(olderJack)

        val person=Person()
    }

    data class User(val name: String, val age: Int)

    /**用户基类**/
    open class Person {
        open fun study() {       // 允许子类重写
            println("我毕业了")
        }
    }

    /**子类继承 Person 类**/
    class Student : Person() {
        val allByDefault: Int=0 // 错误：需要显式初始化器，隐含默认 getter 和 setter
        var initialized = 1 // 类型 Int、默认 getter 和 setter

        override fun study() {    // 重写方法
            println("我在读大学")
        }
    }

    interface MyInterface {
        val prop: Int // 抽象的

        val propertyWithImplementation: String
            get() = "foo"

        fun foo() {
            print(prop)
        }
    }

    class Child : MyInterface {
        override val prop: Int = 29
    }

}